/**
 * @author helio
 */
var TrackRecordMoneyView = Ext.extend(BasicPanel,{
	
	initlize : function() {
		
		if(!this.detailsGrid) {
						
			this.detailsStore = new Ext.data.Store({
			    proxy: new Ext.ux.data.PagingMemoryProxy(this.detailsJson),
			    //remoteSort:true,
			    reader: new Ext.data.JsonReader({
					root: 'records',
					remoteSort: true,
			        fields: ['name', {name:'amount',type:'float'}, 'type', {name:'date',type:'date'},'comment']
			    })
			});
			
			// create paging bar
			var pagingBar = new Ext.PagingToolbar({
		        pageSize: 25,
		        store: this.detailsStore,
		        displayInfo: true,
								
				plugins: new Ext.ux.ProgressBarPager()
		    });
			
			// create the grid
			var csm = new Ext.grid.CheckboxSelectionModel();
			
			this.detailsGrid = new Ext.grid.GridPanel({
				store: this.detailsStore,
				columns: [csm, {
					header: "账户名称",
					dataIndex: 'name',
					width: 80,
					sortable: true
				}, {
					header: "金额",
					dataIndex: 'amount',
					align: 'right',
					sortable: true
				}, {
					header: "入帐/出帐",
					dataIndex: 'type',
					align: 'center',
					width: 70,renderer: SALE.Utils.moneyStatusRenderer.createDelegate(this),
					sortable: true
				}, {
					header: "日期",
					dataIndex: 'date',
					width: 70,
	           		renderer: Ext.util.Format.dateRenderer('Y-m-d'),
					sortable: true
				}, {
					header: "备注",
					dataIndex: 'comment',
					width: 80
				}],
				
				sm: csm,
				
				tbar:['->', '选择查看日期：', {
					xtype:'datefield',
				    name: 'entry_date',							
					format:'Y-m-d',
					
					listeners: {
						'select': function(field, date){
							var query = Ext.util.Format.date(date,"Y-m-d");
							SALE.Action.searchTrackRecordMoney(this.initlizeDataHandler.createDelegate(this),query);
						}.createDelegate(this)
					}
				}],
				
				bbar: pagingBar,
				
				viewConfig: {
			        forceFit: true,
					enableRowBody:true,
		            showPreview:true
			    },
		
				loadMask: true,
				stripeRows: true,
				border: false,
				autoExpandColumn: 'pname',
				layout: 'fit',
				
				listeners: {
					cellclick : function(grid, rowIndex, columnIndex, e) {
						this.selectedRowIndex = rowIndex;
					}.createDelegate(this)
				}
			});
		}
	},
	
	initlizeDataHandler : function(resultJson) {
		this.detailsJson['records'] = resultJson.records;
		this.detailsStore.load({params:{start:0, limit:25}});
	},
	
	getCorePanel : function() {
		if (!this.detailsGrid) {
			this.initlize();
			SALE.Action.searchTrackRecordMoney(this.initlizeDataHandler.createDelegate(this),'');
		}
		return this.detailsGrid;
	}
});

TrackRecordMoneyView.showNextOperatePanel = function(){
	var  view = new TrackRecordMoneyView();	
	SALE.App.showNextOperateTabPanel(view.getCorePanel(),"出入账记录");
}
